local skel = fk.CreateSkill {
  name = "rmt__sixian",
  tags = {Skill.Compulsory},
}

skel:addEffect(fk.DamageCaused, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      local parentUse = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if not parentUse then return end
      local use_data = parentUse.data
      return not (use_data.extra_data and use_data.extra_data.rmt__sixianCount and use_data.extra_data.rmt__sixianCount > 1)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local parentUse = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if not parentUse then return end
    local use_data = parentUse.data
    use_data.extra_data = use_data.extra_data or {}
    use_data.extra_data.rmt__sixianCount = (use_data.extra_data.rmt__sixianCount or 0) + 1
    room:doIndicate(player, {data.to})
    if use_data.extra_data.rmt__sixianCount == 1 then
      player:broadcastSkillInvoke(skel.name, 1)
      room:notifySkillInvoked(player, skel.name, "control", {data.to})
      if not data.to:isNude() then
        local card = room:askToChooseCard(player, {
          target = data.to, skill_name = skel.name, flag = "he",
          prompt = "#rmt__sixian-throw:"..data.to.id,
        })
        room:throwCard(card, skel.name, data.to, player)
      end
    else
      player:broadcastSkillInvoke(skel.name, 2)
      room:notifySkillInvoked(player, skel.name, "negative", {data.to})
      if not data.to.dead then
        room:recover { num = 1, skillName = skel.name, who = data.to, recoverBy = player }
      end
      data:preventDamage()
    end
  end,
})

skel:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill(skel.name) and skill.trueName == "slash_skill"
  end,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:hasSkill(skel.name) then
      return 999
    end
  end,
})

Fk:loadTranslationTable{
  ["rmt__sixian"] = "肆燹",
  [":rmt__sixian"] = "锁定技，你使用【杀】无视距离和目标数限制，且首次造成伤害时，弃置目标一张牌；第二次造成伤害时，改为令目标回复1点体力。",
  ["#rmt__sixian-throw"] = "肆燹:弃置 %src 一张牌",

  ["$rmt__sixian1"] = "成赵者，我也！黄口婢儿，不足复留种。",
  ["$rmt__sixian2"] = "斩首洗血、亵而后杀，和与牛羊煮食，美甚！",
}

return skel
